<?php
class ContentPage extends MX_Controller {
	function ContentPage()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('public_model');
		$this->load->model('contentpage_model');
	}
	function Return_Policy($seller_id=0){
		$is_popup = $this->input->post('is_popup');
		$returnpolicy_content=$this->contentpage_model->getReturnPolicy_Page($seller_id);
		$data['returnpolicy_content']=$returnpolicy_content;
		$content=$this->load->view('returnpolicypage_view', $data,true);
		if($is_popup){
			echo $content;
		}
		else
		{
		Template::display($content);
		}
	}
	function Profile($seller_id=0){
		$is_popup = $this->input->post('is_popup');
		$profile_content=$this->contentpage_model->getProfile_Page($seller_id);
		$data['profile_content']=$profile_content;
		$content=$this->load->view('profile_view', $data,true);
		if($is_popup){
			echo $content;
		}else { Template::display($content);}
	}
	function TermsConditions(){
		$termsconditions_content=$this->contentpage_model->getTermsConditions_Page();
		$data['termsconditions_content']=$termsconditions_content;
		$content=$this->load->view('termsconditions_view', $data,true);
		Template::display($content);
	}
	function managecontentpage($page_name,$page_title){
		if(modules::run('login/is_admin_logged_in') == false){
			if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
				echo OUT_OF_SESSION;
				exit(0);
			}else{redirect('login');}
			return;
		}
		$seller_id=$this->public_model->getSellerId();
		$seller_id= isset($seller_id)?$seller_id:0;
		$content_page = $this->contentpage_model->getContentPage($page_name,$seller_id);
		$data = array();
		if(count($content_page)>0){
			$data = $content_page[0];			
		}
		$data["title"] = $page_title;
		if($page_name=='givemartpolicy'){
			$data['page_title']="Givemart's Policy";
		}else $data['page_title'] = $page_title;
		$content=$this->load->view('editcontentpage_view', $data,true);
		Template::display($content);
	}
	function submitContentPage(){
		if(modules::run('login/is_admin_logged_in') == false){
			if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
				echo OUT_OF_SESSION;
				exit(0);
			}else{redirect('login');}
			return;
		}
		$id = $_POST["id"];
		$content_page = $_POST["content_page"];
		$title = $_POST["content_title"];
		$this->contentpage_model->submitContentPage($id,$content_page);
		// update log 
		if($this->db->affected_rows() > 0){
			$action_id = modules::run('actionlog/saveActionLog',ACTION_UPDATE." content page","Manage content page", $id,"content page: ".$title, $this->session->userdata('email'));
		}
		
		if($_POST["page_name"]=="givemartpolicy"){
			//update user table to accept
			$data = array(
               'accepted_policy' => 0
            );
		 	$this->db->update('seller', $data); 
		}
		echo json_encode(1);
	}
	function view($page_name,$page_title,$seller_id=0){
		$content_page = $this->contentpage_model->getContentPage($page_name,$seller_id);
		$data = array();
		if(count($content_page)>0){
			$data = $content_page[0];			
		}
		$data["title"] = $page_title;
		$content=$this->load->view('contentpage_view', $data,true);
		Template::display($content);
	}
}
?>